class textBox {
  /* textBox class implements a simple scrolling text box
  
  textBox b = new textBox(lines, left, top, width, font_spacing, Font, font_color, background);
  
  lines         is the number of lines of text displayed (int)
  left          is the x position of the text box (int)
  top           is the y position of the text box (int)
  width         is the width of the text box (int)
  font_spacing  is the line spacing of the font selected for the text box (int)
  Font          is the PFont to be used in the text box (PFont)
  font_color    is the text color (color)
  background    is the background color (color)
  
  Methods
  draw()        draws the text box in the main window
  clearText()   clears the text box
  setText(s, i) loads String s into line i
  scrollText(s) scrolls the text up one line and writes String s into the last line of the text box
  
  */
  
  int top, left, lines, fSpace;
  int height, width;
  String[] boxText;
  PFont font;
  color fontColor, backColor;
  
  textBox(int ln, int lf, int tp, int wd, int sp, PFont f, color fc, color bc) {
    top = tp;
    left = lf;
    width = wd;
    lines = ln;
    fSpace = sp;
    font = f;
    height = (lines + 1) * fSpace;
    fontColor = fc;
    backColor = bc;
    
    boxText = new String[lines];
    clearText();
  }
  
  void draw() {
    fill(backColor);
    rect(left, top, width, height);
    fill(fontColor);
    textFont(font);
    textAlign(LEFT, TOP);
    int m = lines / 2;
    int l = 2* m + left;
    m += top;
    for (int ctr = 0; ctr < lines; ctr++) {
      text(boxText[ctr], l, m + fSpace * ctr);
    }
  }
  
  void setText(String s, int i) {
    boxText[i] = s;
  }
    
  void clearText() {
    for (int ctr = 0; ctr < lines; ctr++) {
      boxText[ctr] = "";
    }
  }
  
  void scrollText(String s) {
    for (int ctr = 0; ctr < (lines - 1); ctr++) {
      boxText[ctr] = boxText[ctr + 1];
    }
    boxText[lines - 1] = s;
  }
  
}
